#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QPainter>
#include<QWidget>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //设置窗口属性
    setWindowTitle("GAME");
    resize(700,640);
    //设置背景图
    background.load(":/new/prefix1/C:/Users/Administrator/Desktop/bk1.jpg");

    //实现开始和退出游戏
    startButton=new QPushButton("开始游戏",this);
    startButton->setGeometry(220,300,190,60);//位置
    startButton->setStyleSheet(
        "QPushButton {"
        "    background-color: #4CAF50;"      // 背景颜色
        "   color: white;"                  // 文字颜色
        "   font-family: 'Microsoft YaHei';" // 字体
        "   font-size: 16px;"               // 文字大小
        "   font-weight: bold;"             // 文字加粗
        "   border: none;"                  // 无边框
        "}"
        );
    connect(startButton,&QPushButton::clicked,this,&MainWindow::startGame);

    closeButton=new QPushButton("退出游戏",this);
    closeButton->setGeometry(220,400,190,60);
    closeButton->setStyleSheet(
        "QPushButton {"
        "    background-color: #4CAF50;"
        "   color: white;"
        "   font-family: 'Microsoft YaHei';"
        "   font-size: 16px;"
        "   font-weight: bold;"
        "   border: none;"
        "}"
        );
    connect(closeButton,&QPushButton::clicked,this,&MainWindow::closeGame);

    // 初始化颜色按钮页面(但不显示)
    colorPage = new ColorButtonPage(this);
    colorPage->hide();
}
//绘制函数设置背景图
void MainWindow::paintEvent(QPaintEvent*event)
{
    QPainter painter(this);
    painter.drawPixmap(0,0,width(),height(),background);
    QMainWindow::paintEvent(event);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::startGame()
{
    //隐藏当前页面按钮
    startButton->hide();
    closeButton->hide();
    //更换背景图
    this->setStyleSheet(":/new/prefix1/C:/Users/Administrator/Desktop/bk1.jpg");


    background.load(":/new/prefix1/C:/Users/Administrator/Desktop/bk2.jpg");
    // 显示颜色按钮页面
    colorPage->show();
    colorPage->setGeometry(this->rect());
    colorPage->resetGame();
}
void MainWindow::closeGame()
{
    this->close();
}
